如果选项为“单一选项”,如何显示字符串?

时间:2012-01-13 08:58:30

标签: jquery css

我无法使用此功能,但如果用户选择“单选”,则应显示字符串“Single”并隐藏文本框,否则显示文本框并隐藏字符串“Single”。

但它不断显示文本框,无论选择哪个选项,我都不知道为什么。

Jquery的:

$('.numberAnswerTxt', context).each(function() {
    var $this = $(this);
    var $noofanswersText = '';

    if ($questionType == 'Single Option') {

        $noofanswersText = $("<span class='naRow string' style='display: inline-block;'>Single</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: none;'>")
                               .attr('name', $this.attr('name'))
                               .attr('value', $this.val())

    } else {

        $noofanswersText = $("<span class='naRow string' style='display: none;'>Single</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: inline-block;'>")
                               .attr('name', $this.attr('name'))
                               .attr('value', $this.val())

    }

    $noofanswers.append($noofanswersText);

}); 

的CSS:

.numberAnswerTxtRow{
    float:center;
    width:40px;
    font-size:14px;
    font-weight:bold;
    display:none;
}

.naRow{
    float:center;   
    display:none;
}

2 个答案:

答案 0 :(得分:1)

我认为你正在寻找

alert( $this.val() )

答案 1 :(得分:0)

你不能装饰alert()显示的内容,你不能使用css,alert()的结果的lookandfeel取决于你使用的浏览器。

我建议使用像jquery dialog之类的东西来控制你想要显示的内容