简体   繁体   English

获取jquery元素的值?

[英]Get value of a jquery element?

var $x = $("input[name='" + linkedmodule + "']");
//var x=document.getElementsByName(linkedmodule);

console.log($x);
if ($x !== "" || $x !== "undefined" || $x !== null) {
    linkedid = $x.val();
    linked_module = $x.attr("relatedModule");
    console.log(linkedid);
} else {

}

I am getting an undefined in the linkedid Please could someone help me 我在linkidid中得到一个未定义的消息,有人可以帮我吗

In the above code object ($x) empty check is not proper, 在上述代码对象($ x)中,空检查不正确,

Below is the modified code 下面是修改后的代码

var $x = $("input[name='" + linkedmodule + "']");
//var x=document.getElementsByName(linkedmodule);

console.log($x);
if (!($x === undefined || $x == null || $x.length <= 0)) {
    linkedid = $x.val();
    linked_module = $x.attr("relatedModule");
  console.log("Value of the element : "+ linkedid);
} else {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM