在html javascript中添加图像代替按钮

时间:2015-07-14 09:31:14

标签: javascript jquery html css grails

问题是: 我有" +"和" - "在行的末尾相应地添加和删除行。

而不是" - "图标,我想替换垃圾箱..我尝试用imgsrc替换。但它扭曲了对齐方式。

即使我们从" +"中删除了该框。并保持+单独添加行和删除垃圾箱" - ",这将是伟大的。

任何人都可以帮我解决这个问题吗?代码如下。

 <tr>
                <td align="left">
                <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']"/>
                <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;"/>
                <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']"/>
                <INPUT type="checkbox" name="chk" class="delCheck"/>
                <input type="button" value=" + " title="Add More" class="clone-faculty"/>
                <input type="button" value=" - " title="Remove selected Row" class="remove-faculty"/>
                </td>
            </tr>


    <script>
         $('.clone-faculty').click(function() {  
            var clone = $('.add-child:first').clone(true).appendTo('#itemRows');        
            });

         $(".remove-faculty").click(function(e) {

             if($('.add-child').length > 1)
             {
                 if($(".delCheck:checked").length != $('.add-child').length)
                 {
                  $(".delCheck:checked").closest("table").remove();
                  // $(".add-child").last().remove();
                 }
                 else
                 {
                     alert('You cannot delete all rows.');
                 }
             }
          });
        </script>

3 个答案:

答案 0 :(得分:0)

试试这个:

 <tr>
                <td align="left">
                <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']"/>
                <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;"/>
                <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']"/>
                <INPUT type="checkbox" name="chk" class="delCheck"/>

                <span class="glyphicon glyphicon-add" ng-click=""></span>

                <span  class="glyphicon glyphicon-trash" ng-click=""></span>
                </td>
            </tr>

答案 1 :(得分:0)

我就这样做了:

<td align="left">
        <g:select name="standard[]" id="standard" class="statSele valid" from="${standardList}" value="" noSelection="['':'Select Regulatory Standard...']" />
        <g:select name="standard_version[]" id="standard_version" class="statSele valid" from="${standardversion}" value="" noSelection="['':'Select Version...']" style="width:150px !important;" />
        <g:select name="standard_domainnumbers[]" id="standard_domainnumbers" req="false" class="statSeledomain valid" from="${['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50']}" value="" noSelection="['':'Select Domain...']" />
        <INPUT type="checkbox" name="chk" class="delCheck" />
        <input type="button" value=" + " title="Add More" class="clone-faculty" />

        <img src="https://cdn2.iconfinder.com/data/icons/windows-8-metro-style/128/trash.png" style="width:17px;vertical-align: middle;" title="Remove selected Row" class="remove-faculty">
    </td>

Here is the JSFiddle of how it looks

答案 2 :(得分:0)

<input type="button" value=" + " title="Add More" class="clone-faculty"/>
<input type="button" value=" - " title="Remove selected Row" class="remove-faculty"/> 

替换为以下代码

<img  src=" + src " width="what size you want" title="Add More" class="clone-faculty"/>
<img  value=" - src" width="what size you want" title="Remove selected Row" class="remove-faculty"/>

一旦声明的width属性没有声明高度值,它将会错过您的图像比例