这可能很难解释,但我有这样的数组对象:
myobject = {
"class1" : "value1",
"class2" : "value2",
"class3" : "value3",
...
}
我有脚本
$.each(myobject,function(i,val){
try{
var it=0;
$("." + i).each(function(it){
switch($("." + i)[it].nodeName){
case "SPAN":case "A":case "DIV":
$("." + i).html(val);
break;
case "INPUT":
switch($("." + i).attr("type")){
case "submit":
$("." + i).attr("value",val);
break;
case "text":case "password":case "email":
$("." + i).attr("placeholder",val);
break;
}
break;
case "IMG":
$("." + i).attr("alt",val);
$("." + i).attr("title",val);
break;
}
});
}catch(err){
// Nothing
}
});
span
, a
,的代码效果div
应该是这样的:
Was: <span class="class1"></span>
Is: <span class="class1">value1</span>
对于input
where type=submit
,应该是这样的:
Was: <input type="submit" class="class2" />
Is: <input type="submit" class="class2" value="value2" />
、和的代码效果span
,但这不会设置s。为什么?a
div
input[type=submit]
placeholder