当我通过.aspx.cs创建Button时,按钮不起作用

时间:2015-04-03 02:02:15

标签: javascript c# asp.net

当我在home.aspx文件中执行此操作时,一切正常

<form>
    <button type="button" id="aaa" value="0" onclick="showQuestionJS(this.id)">[time1]: titel1</button>
    <button type="button" id="nnn" value="1" onclick="showQuestionJS(this.id)">[time2]: titel2</button>
    <button type="button" id="rrr" value="2" onclick="showQuestionJS(this.id)">[time3]: titel3</button>

</form>

<script type="text/javascript">
    function showQuestionJS(id_of_the_button)
    {
        alert(document.getElementById(id_of_the_button).value)
    }
</script>

但是当我尝试通过home.aspx.cs创建按钮时,创建了按钮,但是当我点击它时,警报中没有显示id:

home.aspx:

<% tempFucntion(); %>


<script type="text/javascript">
    function showQuestionJS(id_of_the_button)
    {
        alert(document.getElementById(id_of_the_button).value)
    }
</script>

home.aspx.cs:

protected void tempFucntion()
    {
        Response.Write("<button type=\"button\" id=\"fff\" \value=\"3\" onclick=\"showQuestionJS(this.id)\">[time4]: titel4</button>");
    }

我不知道为什么会这样或者如何修复

我想得到一些帮助

1 个答案:

答案 0 :(得分:0)

你有一个额外的反斜杠

id=\"fff\" \value=\"3\"
-----------^