简体   繁体   English

使用jQuery使用PHP插入Select标签

[英]Inserting Select tag with PHP using jQuery

what i'm trying to do is whenever the user click add more button a new select tag will be created i manage to create the select tag but whenever i'm trying to add the options for my select tag it didn't show up here's my code 我想做的是每当用户单击添加更多按钮时,都会创建一个新的选择标签,我设法创建选择标签,但是每当我尝试为我的选择标签添加选项时,它都不会显示在这里我的代码

jQuery : jQuery的:

 $(".addjob").click(function(){

     $("<tr><td>Choose Job Title</td><td><select name='jobtitles_id' class='jobtest' ></select></td></tr>").insertAfter($(this).parents("tr:last"));
     addjobtitle();
 });

Here is my html/php code 这是我的html / php代码

<tr classs="afterthis">
<td>Choose Job Title</td><td><select name="jobtitles_id" style="min-width:145Px"><?php
    $rows1 = array();
    $result1 = $db->query("job_titles", " WHERE id NOT IN (SELECT jobtitles_id FROM categorybridge) ORDER BY name ASC ");
                $selected1 = '';
        while($rows1 = mysql_fetch_array($result1)) {
                    if($rows1['name'] == 'none'){
                    $selected1 = "selected";        
                    }
             ?> 
            <option value="<?php echo $rows1['id']; ?>" <?php echo $selected1; ?>><?php echo ucwords($rows1['name']); ?></option>       
    <?php $selected1 = ''; } ?>
    <option value="26" >None</option>   
    </select></td><td><div class="addjob" >Add another Job Title</div></td>
</tr>

BTW the value from my select tag comes from mySql and i dont know what to do :( 顺便说一句,我的选择标签的值来自mySql,我不知道该怎么办:(

please kindly help me.. thanks in advance! 请帮助我..在此先感谢!

Shot in the dark here, but I think this is what you are trying to do based on code posted. 这里是黑暗的镜头,但我认为这是您根据发布的代码尝试执行的操作。

http://jsfiddle.net/NUET3/1/ http://jsfiddle.net/NUET3/1/

Monitor the table for when addjob is clicked. 监视表中单击addjob时间。 When clicked, clone its table row and append it to the table. 单击后,克隆其表行并将其附加到表中。

$('table').on('click', '.addjob', function() {
    var $clone = $(this).parents('tr').clone();
    $('table').append($clone);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM