English 中文(简体)
广播电台和电视台
原标题:Radiobuttons and jQuery

我在MVC提供了以下无线电台:

<div class="radio" id="ModelViewAd.TypeOfAd">
 <input checked="checked" id="ModelViewAd.TypeOfAd_Ad" name="ModelViewAd.TypeOfAd.SelectedValue" type="radio" value="Ad" />
 <label for="ModelViewAd.TypeOfAd_Ad">Annons</label><br>
 <input id="ModelViewAd.TypeOfAd_Auktion" name="ModelViewAd.TypeOfAd.SelectedValue" type="radio" value="Auktion" />
 <label for="ModelViewAd.TypeOfAd_Auktion">Auktion</label><br>
</div>

现在,我需要根据无线电集团的价值来掩盖红外线。

我曾尝试过:

$(document).ready(function () {

        $("#TypeOfAd_Auktion").click(function () {
            if ($(this).checked) {
                $("divEndDate").css("visibility", "visible");
            }
            else {
                $("divEndDate").css("visibility", "hidden");
            }
        });

        $("#ModelViewAd.TypeOfAd_Ad").click(function () {
            if ($(this).checked) {
                $("divEndDate").css("visibility", "hidden");
            }
            else {
                $("divEndDate").css("visibility", "visible");
            }
        });
    });

如今,其中之一就是在无线电台之间开关时启动的? 如何解决这一问题?

最佳回答

你们需要一些更正:

$("#TypeOfAd_Auktion")
//should be:
$("#ModelViewAd\.TypeOfAd_Auktion")

$(this).checked
//should be:
this.checked

$("#ModelViewAd.TypeOfAd_Ad")
//should be:
$("#ModelViewAd\.TypeOfAd_Ad")

而且:

$("divEndDate")
//should be:
$("#divEndDate")

在使用<代码>时,需要将其越出,使之不作为类别处理,例如/>。 此外,除非你需要<条码>,甚至在暗中使用<条码><<>><>><>> >条码时,在页内占用空间,否则,你可以缩短这一条码:

$("#ModelViewAd\.TypeOfAd :radio").change(function () {
    $("#divEndDate").toggle(this.checked && this.value ==  Ad );
});

http://jsfiddle.net/Yrabr/"rel=“nofollow noreferer”> 您可以在这里看到“号”,这包括不改变你的超文本,即文字。

问题回答

审判:

$(document).ready(function () { 
  $( input:radio[name="ModelViewAd.TypeOfAd.SelectedValue"] ).click(function() {
    this.id ==  ModelViewAd.TypeOfAd_Ad ?
      $("#divEndDate").show() : $("#divEndDate").hide();

  });
});

我们把同一个点击事件手对无线电台的投入捆绑在一起,然后检查该功能内的id。 视这种贴现价值而定,我们要么展示要么隐藏在“<div>”;,到终日。

http://jsbin.com/awune"rel=“nofollow noreferer”





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!