简体   繁体   English

需要帮助以HTML格式的项目符号显示不同的字段

[英]Need help to display different fields with the help of bullets in HTML form

I am trying to mimic the HTML form present on this link: http://maati.tv/uploads/ I am making it to put on a company's Facebook page. 我试图模仿此链接上显示的HTML表单: http : //maati.tv/uploads/我正在将其放在公司的Facebook页面上。

Now, the issue I am running into is that I am unable to display different fields depending upon the select radio button. 现在,我遇到的问题是根据选择单选按钮,我无法显示不同的字段。 I know it requires JavaScript. 我知道它需要JavaScript。 I've got the related script from this link: https://stackoverflow.com/a/14127709/1315163 我已经从此链接获得了相关脚本: https : //stackoverflow.com/a/14127709/1315163

$(".radioSelect").each(function () {
  showSpecificFields(this);
});

$(".radioSelect").click(function () {
  showSpecificFields(this);
});


function showSpecificFields(obj) {
  if ($(obj).is(":checked")) {
    var radioVal = $(obj).val();
    $(".fieldsSpecific").each(function () {
      if ($(this).attr('id') == radioVal) {
        $(this).show();
      } else {
        $(this).hide();
      }
    });
  }
}

Can anyone please help me with it? 有人可以帮我吗? Rest of the code is in this jsFiddle: http://jsfiddle.net/DDJNc/2/ 其余代码在此jsFiddle中: http : //jsfiddle.net/DDJNc/2/

Thanks. 谢谢。

Your answer: 你的答案:

$(".radioSelect").each(function(){
    showSpecificFields(this);
});

$(".radioSelect").click(function(){
   showSpecificFields(this);
});

function showSpecificFields(obj){
    if($(obj).is(":checked")){
    var radioVal = $(obj).val();
     $(".fieldsSpecific").not('.'+radioVal).each(function(){
         $(this).hide(); 
     });
     $(".fieldsSpecific."+radioVal).each(function(){
         $(this).show(); 
     }); 
    }
}

Check the HTML also 还检查HTML

http://jsfiddle.net/DDJNc/4/ http://jsfiddle.net/DDJNc/4/

. (dot) css selector selects elements containing a given class. (点)css选择器选择包含给定类的元素。 That class SHOULD BE present on your HTML for it to work! 该类应该出现在您的HTML上才能正常工作!

Don't use the id attribute for that because you are trying to match a set of elements that belong to a class and not a single element. 不要为此使用id属性,因为您试图匹配属于一个类而不是单个元素的一组元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM