使用Jquery调整动态网址 [英] Using Jquery to adjust a dynamic url

查看:47
本文介绍了使用Jquery调整动态网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码根据下拉选择生成img网址.

I'm using the following code to generate an img url based on a drop down selection.

$(document).ready(function() {
    $('select').change(function(){
       var src = $(':selected', this).text()
       $('img').attr('src', location.hostname + "/" + src + '.jpg');
    });
});`

它用于显示将选择的文本添加到静态URL上,即:

It works for showing adding the select text onto a static a url i.e. :

www.mysite.com/selecttext.jpg

但是需要为这样的事情工作:

But need to work for something like this:

www.mysite.com/<?php text value ?>/selecttext.jpg

PHP已经开始运行,只需要知道如何调整jquery即可工作.

The PHP is already functioning just need to know how to adjust the jquery to work.

推荐答案

PHP/HTML:

<script type="text/javascript"> var dir = '<?php echo "foo"; ?>'; </script>

JS:

$(document).ready(function() {
    $('select').change(function(){
       var src = $(':selected', this).text()
       $('img').attr('src', location.hostname + "/" + dir + '/' + src + '.jpg');
    });
});`

这篇关于使用Jquery调整动态网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆