单选按钮选择未在UI中刷新

时间:2015-06-02 06:48:38

标签: javascript jquery html html5 jquery-ui

第一次无线电选择有效,但如果我第二次选择无线电,那么它不会显示为已选中。属性已检查=已检查在html中显示但在UI中未反映。

它可以反映出什么是解决方案。 这是应用属性的脚本代码。"

  $('#' + myradioid+ ' input:radio').attr("checked", "checked")

这是我的HTML

<ul id="Ulist" class="Ulist1">
    <h2 class="QuestionTxt">First question </h2>
    <li id="117184normal" class="statusDefaultAns">
        <a id="117184" href="#" onclick="Select(117184);">
            <h2>
                <input quiz-option="multiple-radio" id="Radio1" type="radio" name="quiz-radio" res="117184">
                <label style="cursor: pointer" for="117184">true</label>

            </h2>
        </a>

    </li>
    <li id="117185normal" class="statusDefaultAns"><a id="117185" href="#" onclick="Select(117185);">
        <h2>
            <input quiz-option="multiple-radio" id="Radio2" type="radio" name="quiz-radio" res="117185">
            <label style="cursor: pointer" for="117185">false</label>

        </h2>
    </a>

    </li>
    <li id="117352normal" class="statusDefaultAns">
        <a id="117352" href="#" onclick="Select(117352);">
            <h2>
                <input quiz-option="multiple-radio" id="Radio3" type="radio" name="quiz-radio" res="117352">
                <label style="cursor: pointer" for="117352">ws</label>

            </h2>
        </a>

    </li>
</ul>

Plz为此提供了一个解决方案,以便无线电选择可以用ui刷新。

由于 Dalvir

1 个答案:

答案 0 :(得分:2)

尝试.prop而不是attr:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mvc.demo.model.Authenticate;


public class LoginController extends HttpServlet {

    private static final long SerialVersionUID=1L;

    public LoginController()
    {
        super();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String s1=req.getParameter("username");
        String s2=req.getParameter("password");
        RequestDispatcher rd=null;

        Authenticate au=new Authenticate();
        String result=au.authorise(s1, s2);

        if(result.equals("success"))
        {
            rd=req.getRequestDispatcher("/success.jsp");

//The error was with this line
            rd.forward(req, resp);
        }
        else
        {

            PrintWriter out = resp.getWriter(  );
            out.print("Sorry UserName or Password Error!");
            rd=req.getRequestDispatcher("/login.html");  
            rd.include(req, resp);  

        }

    }

}

更好的是,尝试使用标签上的onclick方法而不是行。选择自己选择的东西可能会导致无限循环,这可以解释你的问题。试试这段代码:

&#13;
&#13;
$('#' + myradioid+ ' input:radio').prop("checked", true)
&#13;
window.Select = function(id) {
    $('#' + id + 'normal input[type="radio"]').click();
};
&#13;
&#13;
&#13;