JQuery:如何更改;image.png“;img的src属性的一部分
我试图在检测到特定的信用卡模式时简单地更改图像 因此,我的代码从以下内容开始:JQuery:如何更改;image.png“;img的src属性的一部分,jquery,Jquery,我试图在检测到特定的信用卡模式时简单地更改图像 因此,我的代码从以下内容开始: <div class="form-group cc-number-group"> <label for="cc-number" class="control-label">Card number <small class="text-muted">[<span class="cc-brand"></span>]<
<div class="form-group cc-number-group">
<label for="cc-number" class="control-label">Card number <small class="text-muted">[<span class="cc-brand"></span>]</small></label>
<div class="input-group">
<input style="border-right: 0;" id="cc-number" type="tel" size="20" data-stripe="number" class="form-control cc-number card-generic form-control input-sm" autocomplete="cc-number" />
<div class="input-group-addon">
<img height="16px" class="credit-card-icon" src="/bundles/bundlename/images/credit.png" />
</div>
</div>
</div>
因此,例如,如果我输入一张Visa信用卡,新的供应商
就是“Visa”
现在,如果我执行console.log(newPath)
操作,控制台将记录127.0.0.1/bundles/bundlename/images/visa.png
,但是src
属性设置为,bundles,bundlename,images,visa.png
,因此我收到一个错误:
404(未找到)
但是,除了错误之外,也许还有一种更简单的方法。。。有人能给我一些建议吗
newPath = document.domain + path.join('/');
$('.credit-card-icon').attr('src', path);
您将newPath
设置为与/
连接的路径,甚至将其包含在控制台.log(newPath)
中,但随后您将src设置为路径。我认为应该是:
$('.credit-card-icon').attr('src', newPath);
您将newPath
设置为与/
连接的路径,甚至将其包含在控制台.log(newPath)
中,但随后您将src设置为路径。我认为应该是:
$('.credit-card-icon').attr('src', newPath);
JSBIN-URL:
equals
比数组中的push
和pop
更快
JQUERY
ctr=0;
$('button').click(function(){
var t =$('input').val();
$('p').html(t);
arr= t.split('/');
arr[arr.length-1]=ctr+".pmg";
newPath=arr.join("/")
$('p').html(newPath);
ctr++;
});
HTML
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
<input type="text"/>
<button>OK</button>
<p></p>
好啊
JSBIN-URL:
equals
比数组中的push
和pop
更快
JQUERY
ctr=0;
$('button').click(function(){
var t =$('input').val();
$('p').html(t);
arr= t.split('/');
arr[arr.length-1]=ctr+".pmg";
newPath=arr.join("/")
$('p').html(newPath);
ctr++;
});
HTML
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
<input type="text"/>
<button>OK</button>
<p></p>
好啊
-。-“谢谢你,也许我厌倦了。。。无论如何,我还添加了document.location.origin
以获取完整的URL。--'谢谢,也许我已经厌倦了。。。无论如何,我还添加了document.location.origin
以获取完整的URL。