小编yok*_*010的帖子

简单的赋值运算符在Python中变得复杂

我在python中声明了四个变量[a = 1,b = 2,c = 3,d = 0],并使用','和'='(简单赋值运算符)将它们换成一行代码.

我有多个答案,并感到困惑.请帮我...

情况1:

a=1
b=2
c=3
d=0
a=a,b=b,c
print "a = " + str(a)
print "b = " + str(b)
print "c = " + str(c)
print "d = " + str(d)
Run Code Online (Sandbox Code Playgroud)

案例1的输出:

a = 2
b = 3
c = 3
d = 0
Run Code Online (Sandbox Code Playgroud)


案例2:

a=1
b=2
c=3
d=0
b=a,b=b,c
print "a = " + str(a)
print "b = " + str(b)
print "c = " + str(c)
print "d = …
Run Code Online (Sandbox Code Playgroud)

python operators variable-assignment

3
推荐指数
1
解决办法
253
查看次数

document.createElement不起作用

我正在使用jQuery库创建一个插件.

这里我将String.prototype存储在变量中,然后我使用此变量来扩展我的Sting对象.这工作正常.

// String Prototyping store in a variable
// Save bytes in the minified version of js
var StrProto = String.prototype;
String.prototype.toProperCase = function () {
  return this.replace(/\w\S*/g, function (txt) {
    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  });
};
// working fine
alert("yogesh kumar".toProperCase());
Run Code Online (Sandbox Code Playgroud)

在下一种情况下,我正在创建存储在abc变量中的m 函数xyz, 这也正常工作.

function xyz(x){
  alert(x)
}
var abc = xyz;
// working fine
abc("yogesh kumar");
Run Code Online (Sandbox Code Playgroud)

在最后一种情况下,我将document.createElement存储在变量 标签中,并使用标签创建一个按钮.但这不起作用.

var tag=document.createElement;
$(document.createElement("button")).html("document.Element").appendTo("#myDiv");

// not working
$(tag("button")).html("tag").appendTo("#myDiv");
Run Code Online (Sandbox Code Playgroud)

请检查jsFiddle上的链接:

点击这里

错误:

在Chrome中 …

javascript jquery

0
推荐指数
2
解决办法
1万
查看次数