Javascript 如何在jQuery+;JQM

Javascript 如何在jQuery+;JQM,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我正在创建一个演示,其中我在按钮单击中生成行。我想在单击生成行“它在容器中生成另一行”时编辑它的文本。我们是否可以在单击编辑按钮时提供一个选项来更改行的文本。当您按完按钮后,会弹出一些东西?是否将文本保存在相同的id上 函数createTestCase(testCaseName、iscreatedFromScript、jsonObject){ 变量id; if(typeof($(“#testCaseContainer li:last”).attr('id'))=='undefined'){ i

我正在创建一个演示,其中我在按钮单击中生成行。我想在单击生成行“它在容器中生成另一行”时编辑它的文本。我们是否可以在单击编辑按钮时提供一个选项来更改行的文本。当您按完按钮后,会弹出一些东西?是否将文本保存在相同的id上

函数createTestCase(testCaseName、iscreatedFromScript、jsonObject){
变量id;
if(typeof($(“#testCaseContainer li:last”).attr('id'))=='undefined'){
id=“tc_1”;
}否则{
id=$(“#testCaseContainer li:last”).attr('id');
var指数=id.indexOf(“”);
var count=id.substring(索引+1,id.length);
count=parseInt(count);
id=id.substring(0,索引)+“”+parseInt(计数+1);
}
var html=''+'
    '+'
  • 编辑
  • '+'
'+'; $('#testCaseContainer')。追加(html); var elem=document.getElementById('testCaseContainer');//只需向下滚动行 elem.scrollTop=elem.scrollHeight; }
请找到下面的示例代码,它将复制您希望使用jqm在代码中实现的场景。将下面的代码保存为html,然后单击“添加文本大小写”并单击“更改文本”按钮

<!DOCTYPE html> 
<html> 
<head> 
<title>My Page</title> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.js"></script>
</head> 
<body> 
<div data-role="page">

   <div data-role=" content ">
   <div class="contentsubbox" id="testCaseContainer">
   <div class="testcaselist_row"><ul  id="testCaseLists" data-role="listview" data-theme="a"></ul></div>
 </div>
 </div>

 <footer id="firstPageFooter">
    <button class="addtestbtn" id="addTestCase" data-theme="a" style="color: #ffffff!important;">Add Test Case</button>

 </footer>
 </div>

<script>
$( document ).ready(function() {
console.log( "ready!" );
});

$('#addTestCase').click(function () {

    createTestCase("trdt",false,null);

});
$('#testCaseLists').delegate('li', 'tap', function () {
console.log('put your text changing logic here');
$(this).find('a:first').text('text u want to change');//text function shud contain the text
});

function createTestCase(testCaseName,iscreatedFromScript,jsonObject) {
console.log("create test case");
var id;
if ($("div.contentsubbox").find("ul li").length == 0){
    id = "tc_1";
} else {
    id = $("#testCaseContainer").find("ul li:last").attr('id');
    var index = id.indexOf("_");
    var count = id.substring(index + 1, id.length);
    count = parseInt(count);
    id = id.substring(0, index) + "_" + parseInt(count + 1);
}

var html = "<li id="+ id +" class='clickTestCaseRow'><a href='#' style='color:   #ffffff!important;'>" + testCaseName + "</a><a class='delete deleteTestCase_h'></a><button class='editclass' style='width:200px !important'>Change text</button ></li>";
$('#testCaseLists').append(html);
$('#testCaseLists').listview('refresh');
var elem = document.getElementById('testCaseContainer'); // just to scroll down the line
elem.scrollTop = elem.scrollHeight;



 }


</script>

</body>
</html>

我的页面
    添加测试用例 $(文档).ready(函数(){ console.log(“准备就绪!”); }); $('#addTestCase')。单击(函数(){ createTestCase(“trdt”,false,null); }); $('#testCaseLists')。委托('li','tap',函数(){ log('put your text changing logic here'); $(this).find('a:first').text('text u want to change');//文本函数shud包含文本 }); 函数createTestCase(testCaseName、iscreatedFromScript、jsonObject){ log(“创建测试用例”); 变量id; if($(“div.contentsubbox”).find(“ul li”).length==0){ id=“tc_1”; }否则{ id=$(“#testCaseContainer”).find(“ul-li:last”).attr('id'); var指数=id.indexOf(“”); var count=id.substring(索引+1,id.length); count=parseInt(count); id=id.substring(0,索引)+“”+parseInt(计数+1); } var html=“
  • 更改文本
  • ”; $(“#测试用例列表”).append(html); $('#TestCaseList')。listview('refresh'); var elem=document.getElementById('testCaseContainer');//只需向下滚动行 elem.scrollTop=elem.scrollHeight; }

    如果您需要更多帮助,请添加评论。

    我只是想问为什么我的fiddleDude无法使用它。您在问题中没有提到这一点!!!在创建问题时,请具体说明您需要什么。
    <!DOCTYPE html> 
    <html> 
    <head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.js"></script>
    </head> 
    <body> 
    <div data-role="page">
    
       <div data-role=" content ">
       <div class="contentsubbox" id="testCaseContainer">
       <div class="testcaselist_row"><ul  id="testCaseLists" data-role="listview" data-theme="a"></ul></div>
     </div>
     </div>
    
     <footer id="firstPageFooter">
        <button class="addtestbtn" id="addTestCase" data-theme="a" style="color: #ffffff!important;">Add Test Case</button>
    
     </footer>
     </div>
    
    <script>
    $( document ).ready(function() {
    console.log( "ready!" );
    });
    
    $('#addTestCase').click(function () {
    
        createTestCase("trdt",false,null);
    
    });
    $('#testCaseLists').delegate('li', 'tap', function () {
    console.log('put your text changing logic here');
    $(this).find('a:first').text('text u want to change');//text function shud contain the text
    });
    
    function createTestCase(testCaseName,iscreatedFromScript,jsonObject) {
    console.log("create test case");
    var id;
    if ($("div.contentsubbox").find("ul li").length == 0){
        id = "tc_1";
    } else {
        id = $("#testCaseContainer").find("ul li:last").attr('id');
        var index = id.indexOf("_");
        var count = id.substring(index + 1, id.length);
        count = parseInt(count);
        id = id.substring(0, index) + "_" + parseInt(count + 1);
    }
    
    var html = "<li id="+ id +" class='clickTestCaseRow'><a href='#' style='color:   #ffffff!important;'>" + testCaseName + "</a><a class='delete deleteTestCase_h'></a><button class='editclass' style='width:200px !important'>Change text</button ></li>";
    $('#testCaseLists').append(html);
    $('#testCaseLists').listview('refresh');
    var elem = document.getElementById('testCaseContainer'); // just to scroll down the line
    elem.scrollTop = elem.scrollHeight;
    
    
    
     }
    
    
    </script>
    
    </body>
    </html>