JQuery检查是否需要inout(JQuery check if the inout is required or not)
在我的HTML模板中,我需要为特定输入设置为False。
<div class="col-xs-2"> <input type="text" required="false" class="product-data form-control" id="description" placeholder="Description" name="description"/> </div>我想打印JQuery中所需的值。
console.log("Value - " + $(this).attr("required"));输出:
价值 - 必需
我希望它打印假。 有没有办法做到这一点。
In my HTML template, I have required set to False for a specific input.
<div class="col-xs-2"> <input type="text" required="false" class="product-data form-control" id="description" placeholder="Description" name="description"/> </div>I want to print the value of required in JQuery.
console.log("Value - " + $(this).attr("required"));Output :
Value - required
I want it to print false. Is there any way to do this.
最满意答案
尝试使用getAttribute() :
document.getElementById('description').getAttribute('required')希望这可以帮助。
console.log("Value - " + document.getElementById('description').getAttribute('required'));<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="col-xs-2"> <input type="text" required="false" class="product-data form-control" id="description" placeholder="Description" name="description"/> </div>Try to use getAttribute() :
document.getElementById('description').getAttribute('required')Hope this helps.
console.log("Value - " + document.getElementById('description').getAttribute('required'));<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="col-xs-2"> <input type="text" required="false" class="product-data form-control" id="description" placeholder="Description" name="description"/> </div>
更多推荐
发布评论