如何在jquery中使用smarty变量
How to use smarty variable inside jquery?
是否可以在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}
试试这个
{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}
编辑:当我写帖子时,看到你解决了这个问题:-(
尝试删除代码中的{literal}
标记。
{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>
{/literal}
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);
使用文字打开-关闭标记。。。工作良好。。。。。。。。。。。。。。
相关文章:
- 将函数的上下文应用于javascript变量
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- 将PHP变量传递给jQuery时遇到问题
- 如何将smarty变量与javascript变量进行比较
- Smarty-可以't将变量内容插入javascript
- javascript函数中的smarty变量
- 如何使用Smarty通过函数传递javascript变量
- 给jquery选择器指定一个smarty变量
- 如何在smarty中读取PHP数组到Java脚本变量
- 文档.getElementById与SMARTY变量
- javascript中的Smarty变量
- 将变量PHP Smarty传递给Javascript
- 在Smarty模板中使用javascript函数中的PHP变量
- 将JavaScript变量分配给Smarty变量
- 我如何创建一个变量在Smarty和填充这个变量与html代码
- 将JavaScript变量传递给smarty
- 从PHP传递给Smarty和Javascript的变量
- 在jQuery函数中使用smarty变量
- 如何在jquery中使用smarty变量