gpt4 book ai didi

c# - jquery mvc4 中的对象不支持此属性

转载 作者:行者123 更新时间:2023-12-01 02:44:01 24 4
gpt4 key购买 nike

@Scripts.Render("~/bundles/jquery", "~/bundles/jqueryui", "~/bundles/WorkbenchScripts")
@Styles.Render("~/Content/WorkbenchCss")
<script type="text/javascript">

$(document).ready(function () {
checkSpecialChars('#txtCreateSet');
$('#btnCancelSet').click(function (e) {
window.close();
});
});


//this function is used to allow only specific characters in function
function checkSpecialChars(textboxID) {
debugger;

return textboxID.each
(
function () {
var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
allowedChars += "abcdefghijklmnopqrstuvwxyz";
allowedChars += "0123456789";
allowedChars += " "; //Space
//Check if try to specifying allowed special characters for Name fields
allowedChars += "-_";
//on keypress
$(textboxID).keypress(function (e) {
var keyUniCode = !e.charCode ? e.which : e.charCode;

var charValue = String.fromCharCode(keyUniCode);

if (keyUniCode != 13) {
if (allowedChars.indexOf(charValue) == -1)
e.preventDefault();
}
});
//On paste
$(textboxID).bind('paste', function (e) {
setTimeout(function () {
var newText = textboxID.val();
$.each(newText, function (i) {
if (allowedChars.indexOf(newText.charAt(i)) == -1)
{ textboxID.val(textboxID.val().replace(newText.charAt(i), '')); }
});
}, 1);
});
}
);
};
</script>






<table>
<tr>
<td>
@Html.Label("Create Set")
</td>
<td>
@Html.TextBoxFor(model => model.SetName, new { id = "txtCreateSet" })
</td>
</tr>
<table>

在上面的代码中,我收到错误“对象不支持此属性”,我使用的是 MVC4,在这里我在 mvc View 中编写了代码,在文本框中只允许使用 0-9 a-z A-Z - _和空格字符。我哪里做错了?任何人都可以帮助我获得所需的解决方案吗?

最佳答案

这是因为您向函数传递的是选择器字符串,而不是对象。

看这里:

checkSpecialChars('#txtCreateSet');

这意味着当您执行以下操作时,您将收到该错误,因为字符串上没有 each 方法:

return textboxID.each

试试这个,传递 jQuery 对象:

checkSpecialChars($('#txtCreateSet'));

关于c# - jquery mvc4 中的对象不支持此属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16716809/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com