是否可以在jquery函数中使用smarty变量?例如:我有/{$country}/{$lang}/8_about-ats.html
,我需要在Jquery:location.href = $(this).data('smarty_code_here');
的数据括号之间放置这段代码。非常感谢你。
Jquery的:
{literal}
<script type="text/javascript">
$(document).ready(function() {
$('#about_ats h3 a').click(function(e){
$(this).attr('href',"/{$country}/{$lang}/8_about-ats.html");
});
});
</script>
{/literal}
HTML:
<div id="about_ats" data-role="collapsible">
<h3><a href="#">About ATS</a></h3>
</div>
Jquery完整代码:
<script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
{literal}
<script type="text/javascript">
$(document).on("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
{/literal}
<script type="text/javascript" src="/js/jquery.mobile-1.2.1.min.js"></script>
{literal}
<script type="text/javascript">
$(document).ready(function() {
var arr = location.href.split("/")
var hostname = arr[2];
var countryCode = arr[3];
var languageCode = arr[4];
if(window.location.href == "http://"+hostname+"/"+countryCode+"/"+languageCode+"/" || window.location.href == "http://"+hostname+"/"+countryCode+"/"+languageCode+"/1_reseni-pro-prumyslovou-a-procesni-automatizaci-kvalitu-a-it.html"){
$('#nav').show();
$('#nav h4').hide();
$('#nav h4 a').trigger('click');
}else{
$('#nav').hide();
$('#nav h4').hide();
}
$('#languages').hide();
$('.search').hide();
$('.contacts').hide();
$('#menu').click(function(e){
e.preventDefault();
$('#nav').slideToggle('300');
if($("#nav").css('visibility') == 'hidden') {
}else{
$('#nav h4 a').trigger('click');
}
});
$('#search_menu').click(function(e){
e.preventDefault();
$('.search').slideToggle('300');
});
$('#globe_menu').click(function(e){
e.preventDefault();
$('.contacts').slideToggle('300');
if($(".contacts").css('visibility') == 'hidden') {
}else{
$('.contacts h2 a').trigger('click');
}
});
$('#lang_menu').click(function(e){
e.preventDefault();
$('#languages').slideToggle('300');
if($("#languages").css('visibility') == 'hidden') {
}else{
$('#languages h4 a').trigger('click');
}
});
$('#about_ats h3 a').click(function(){
{/literal}
alert("/{$country}/{$lang}/8_about-ats.html");
{literal}
});
});
</script>
{/literal}
答案 0 :(得分:2)
试试这个
{literal}
<script type="text/javascript">
$(document).ready(function() {
$('#about_us h3 a').click(function(e){
$(this).attr('href',"/{/literal}{$country}/{$lang}{literal}/8_about-ats.html");
});
});
</script>
{/literal}
编辑: 看到你在我写完帖子时解决了这个问题: - )
答案 1 :(得分:0)
尝试删除代码中的{literal}
代码。
<击> {字面} 击>
<script type="text/javascript">
$(document).ready(function() {
$('#about_us h3 a').click(function(e){
$(this).attr('href',"/{$country}/{$lang}/8_about-ats.html");
});
});
</script>
<击> {/文字} 击>
答案 2 :(得分:0)
var data="<tr><td><input type='checkbox' class='case'/></td><td><label>{/literal}{$smarty.session.full_name|@ucfirst}{literal}</label></td>";
data +="<td><input type='text' id='i_tour_date"+i+"' class='se' name='tour_date[]'/></td></tr>";
$('#sds').append(data);
使用文字开放式关闭标签......运作良好..............