我需要从html传递一个值并使用它在我的Js中查找var,因此根据我的html上的theId中的值,我可以在我的js中使用该var。我怎样才能做到这一点?在js中使用通过的val
HTML
<input id="Waist" type="checkbox" onchange="getToWork(this.id)" >Waist
<script>
对HTML标签
function getToWork(theId){
usedCheckBox(theId);
}
myJs.js
function usedCheckBox(theId){
var temp1 = theId.name; - will be undefined
var temp2 = Waist.name; - will work
}
var Waist = {name:"bob",age:"17"}
* “将是不确定的” *那不可能。它应该会抛出一个错误。 'Waist.val();'相同。 **字符串**没有'val()'方法。 (但是,'Waist'有可能指DOM元素而不是字符串)。 –