我目前在尝试使用 jquery .value
获取文本框中的值时感到困惑
<input class="input referral-code" disabled="true" ng-model="account.referral_code_string" id="input-refcode">
我尝试使用 document.getElementById('input-refcode').value
尝试获取该值,但在我的控制台上显示为空。
但是,如果我尝试将其绑定(bind)到 on-click
事件上,它会设法获取存储在 ng-model
内的值
$('.trigger').on('click', function(){
console.log(document.getElementbyId('input-refcode'))
});
正如您所看到的,文本框本身内有一个值。但是当你尝试检查它时,结果是这样的。
<input class="input referral-code" disabled="true" ng-model="account.referral_code_string" id="input-refcode">
如果您查看输入文本框
内没有值
。我不确定它是否与angular.js
最佳答案
您可以使用元素获取scope
对象
var scope = angular.element(document.getElementById('input-refcode')).scope();
var desiredValue = scope.account.referral_code_string;
关于javascript - 使用 javascript .value 获取文本框 ng-model 内的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43992718/