在MVC中使用jquery获取帮助器长度的textbox
我有Html.TextBoxFor和submit按钮。我的意图是,如果文本框为空,则按钮将隐藏。我试图通过以下方式实现这一目标:在MVC中使用jquery获取帮助器长度的textbox,jquery,model-view-controller,textbox,Jquery,Model View Controller,Textbox,我有Html.TextBoxFor和submit按钮。我的意图是,如果文本框为空,则按钮将隐藏。我试图通过以下方式实现这一目标: @Html.TextBoxFor(model => model.Tytul, new { id="tytulTextBox", @class = "tytulTextBoxDodajtresc" }) <script type="text/javascript"> $(document).ready(function () {
@Html.TextBoxFor(model => model.Tytul, new { id="tytulTextBox", @class = "tytulTextBoxDodajtresc" })
<script type="text/javascript">
$(document).ready(function () {
var button = document.getElementById("DodajTrescButton");
var myLength = $("#tytulTextBox").val().length;
if (myLength > 0) {
button.style.display = "block";
}
});
</script>
@Html.TextBoxFor(model=>model.Tytul,新的{id=“tytulTextBox”,@class=“tytulTextBoxDodajtresc”})
$(文档).ready(函数(){
var button=document.getElementById(“DoDajTresButton”);
var myLength=$(“#tytulTextBox”).val().length;
如果(我的长度>0){
button.style.display=“block”;
}
});
我做错了什么?。我对jquery非常陌生,但使用jquery似乎是实现我想要的最简单的方法 我认为你的if中缺少了else条款
if (myLength > 0) {
$(button).css("display","block");
}
else{
$(button).css("display","none");
}
谢谢你的回答。我试着按照你说的做,但还是一样,什么也没发生。最后我解决了一个问题。您的评论非常有用,非常感谢:)