Tag: 用户自定义

在jquery中调用用户定义的函数

我想在jQuery中调用用户定义的函数。 $(document).ready(function() { $('#btnSun').click(function() { myFunction(); }); $.fn.myFunction = function() { alert('hi'); } }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="btnSun">Say hello!</button> 我也尝试了以下 $(document).ready(function() { $('#btnSun').click(function() { myFunction(); }); }); function myFunction() { alert('hi'); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="btnSun">Say hello!</button> 它似乎没有工作! 任何想法,我错了吗?

Python中如何处理__eq__以什么顺序?

由于Python不提供比较运算符的左/右版本,它如何决定调用哪个函数? class A(object): def __eq__(self, other): print "A __eq__ called" return self.value == other class B(object): def __eq__(self, other): print "B __eq__ called" return self.value == other >>> a = A() >>> a.value = 3 >>> b = B() >>> b.value = 4 >>> a == b "A __eq__ called" "B __eq__ called" False 这似乎同时调用__eq__函数。 […]