@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视图中编写了代码,在文本框中仅允许使用0-9 az AZ字符-_和空格字符我在哪里做错了?有人可以帮助我获得所需的解决方案吗?
参考方案
那是因为您要向函数传递选择器字符串,而不是对象。
看这里:
checkSpecialChars('#txtCreateSet');
这意味着当您执行以下操作时,将出现该错误,因为字符串上没有each
方法:
return textboxID.each
试试这个,传递jQuery对象:
checkSpecialChars($('#txtCreateSet'));
ddl在服务器中未更新-asp.net - javascript我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……
ASP.NET-如何更改JSON序列化的方式? - javascript我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …
ASP.NET MVC中应为DataTable返回哪种数据? - javascript我想为DataTable中的每个页面创建动态加载信息。我正在尝试遵循以下示例:https://www.datatables.net/manual/server-sidehttps://www.datatables.net/manual/data来自示例的代码:$('#example').DataTable( { serverSide: t…
Asp.Net:在服务器端还原DropDownList的客户端SelectedItem - c#因此,我的页面上有一个dropDownList,其中包含数百个项目。用户可以通过在文本框中键入一些文本来过滤此DDL。然后对DDL进行相应的过滤(所有不包含输入文本的项目都将通过JavaScript删除)。然后,用户选择他的项目并按下按钮。通常,这将导致错误,因为DDL已更改并且ASP验证了PostBack数据。但是,使用EnableEventValidat…
asp.net mvc中的对象数组数据始终为null - javascript我需要通过json将对象数组发送到asp.net mvc 2,但是我在mvc控制器中没有得到null对象是这样的entries[1].date = "12/22/2014" entries[1].Ref = "0002" entries[1].Credit = "100" entries[2].da…