无法使用Jquery获取动态文本字段值

时间:2013-07-30 09:17:51

标签: javascript

我无法获得动态文本字段值。请参阅下面的jquery代码。

我在为LandMark创建文本字段时添加了onclick事件。请参阅以下代码。 我总是得到不确定。请帮帮我。

function dynamicEvent(){

     alert("dynamic event");
     $(document).ready(function(){
     alert("inside ajax --> dynamic");

     var table = document.getElementById("dataTable");
     alert("table-->"+table);
     var rowCount = table.rows.length;         
     alert("rowCount-->"+rowCount);
     alert("value of rowCount"+rowCount);           
     var uniqueId;
     for (var i=rowCount;rowCount>7;i++){

        uniqueId = i;
        alert("inside for loop");
        alert("uniqueId-->"+uniqueId);

        var element = document.createElement("input");
        uniqueId=uniqueId-1;   

            element.id = "t02Travelfrom" +uniqueId;


            var tfrom=element.id; 

            alert("tfrom id-->"+tfrom);

            var t02Travelfrom=$("tfrom").val();

            alert(tfrom+"--value-->" +t02Travelfrom);

        }

     });

 }

2 个答案:

答案 0 :(得分:0)

您的选择器不正确:

var t02Travelfrom=$("tfrom").val();

更改为:

var t02Travelfrom=$("#" + tfrom).val();

答案 1 :(得分:-1)

$("tfrom")返回标记为tfrom

的元素

您需要$(tfrom)。你不需要双重配额。