$(selector).attr(attribute,value)
$.post()

在jqery中有这样一个方法,$.post()下面就这个方法做一个简单的实例:

jQuery.post( url, [data], [callback], [type] ) :
使用POST方式来进行异步请求

参数:

url (String) : 发送请求的URL地址.

data (Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。

callback (Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。

type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)

<ul class="am-tabs-nav am-nav am-nav-tabs">
<li class="am-active"><a href="#true" onclick="set('true')">出售中</a></li>
<li><a href="#false" onclick="set('false')"
class="<{if $status =='false'}>am-text-danger<{/if}>">已下架</a></li>
</ul>  '#email').val(),address:$('#address').val()},
<script type="text/javascript">
function set(value){
$.post("<{link app=subsales ctl=wap_subshop act=products}>", { type: value},
function(data){
}, "json");
}
</script>
  <button type="button" class="am-btn am-btn-primary js-modal-open">打开 Modal</button>
<button type="button" class="am-btn am-btn-secondary js-modal-close">关闭 Modal</button>
<button type="button" class="am-btn am-btn-danger js-modal-toggle">Toggle Modal</button> <div class="am-modal am-modal-no-btn" tabindex="-1" id="your-modal">
<div class="am-modal-dialog">
<div class="am-modal-hd">Modal 标题
<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
</div>
<div class="am-modal-bd">
Modal 内容。
</div>
</div>
</div>
<script>
$(function() {
var $modal = $('#your-modal'); $modal.siblings('.am-btn').on('click', function(e) {
var $target = $(e.target);
if (($target).hasClass('js-modal-open')) {
$modal.modal();
} else if (($target).hasClass('js-modal-close')) {
$modal.modal('close');
} else {
$modal.modal('toggle');
}
});
});
</script>

弹框效果

上述代码是amaze ui里的一个弹窗效果,该功能符合要求。

问题。现在对每个商品中《推广》要求都有弹窗效果,因为每个产品都有不一样的id,所以上述js需要进行处理,每个产品推广,都写一个js?,答案肯定是no,思考,如何高效,只用一个js方法来实现呢?
方法,因为每个产品的id不一样所以可以,那个产品需要请求弹框就需要发送一次请求,异步处理,后台输出产品所对应的信息
代码
后台代码:根据产品id来获取产品对应的信息
   //生成二维码
function qrcode_image()
{ $product_id = $_POST['product_id'];
// $url ="http://www.taifengmall.com".$this->gen_url(array('app' => 'subsales', 'ctl' => 'wap_subshop', 'act' => 'product', 'args' => array($product_id)));
$url = kernel::base_url(1).$this->gen_url(array('app' => 'subsales', 'ctl' => 'wap_subshop', 'act' => 'product', 'args' => array($product_id)));
$qrcode_image_id = kernel::single('weixin_qrcode')->generate($url, '10');
$img = base_storager::image_path($qrcode_image_id, 's');
echo $img; }

html 代码

问题:例如< img id="xxx" src=" xxx"/> 其中如何替换src图片的链接呢?

方法,$(selector).attr(attribute,value)设置被选元素的属性和值

<a data-am-modal="{target: '#q-img-modal'}" class="am-btn am-btn-xs" href="javascript:;" onclick="setimg('<{$product.product_id}>')">
推广
</a>
<div class="am-popup" id="q-img-modal">
<div class="am-popup-inner">
<div class="am-popup-hd">
<h4 class="am-popup-title">长按二维码图片保存发送</h4>
<span data-am-modal-close class="am-close">&times;</span>
</div>
<div class="am-popup-bd am-text-center">
<img id="t-img" src="" class="am-img-responsive"/>
</div>
</div>
</div>
<script type="text/javascript"> function setimg(value){ $.post("<{link app=subsales ctl=wap_subshop act=qrcode_image}>", { product_id:value},
function(data){
$('#t-img').attr('src',data);//替换代码信息
$('#q-img-modal').modal(options);//弹窗
}, "text");
} function set(value){
$.post("<{link app=subsales ctl=wap_subshop act=products}>", { type: value},
function(data){
}, "json");
}
</script>

效果

php 与 jquery中$.post()与attr()方法的简单实例 amaze modal 模态窗口的更多相关文章

  1. jquery 实践操作:attr()方法

    此篇要记录的是 关于 jquery  的 attr() 方法 在JS中设置节点的属性与属性值用到setAttribute(),获得节点的属性与属性值用到getAttribute(),而在jquery中 ...

  2. jQuery通用的全局遍历方法$.each()用法实例

    1.jQuery通用的全局遍历方法$.each()用法 2. test.json文件代码: 3. html代码 4.jQuery代码 <script src="jquery-1.3.1 ...

  3. 使用jQuery的".css()"和".attr()"方法设置元素"left"属性的注意点

    今天在使用jQuery方法".css()"设置"ajax-loader.gif"的位置时出了点小状况,关键代码如下(为了简化,这里假定要给"ajax- ...

  4. jQuery的prop和attr方法之间区别

    JQuery.attr(): Get the value of an attribute for the first element in the set of matched elements. J ...

  5. jquery中prop()与attr()方法的区别

    一.prop() 简单来说是当需要判断真假时使用,如复选框时: if( $(this).prop('checked')){ //当返回true时在这里调用 }else{ //当返回false时在这里调 ...

  6. jquery中$.post()方法的简单实例

    在jqery中有这样一个方法,$.post()下面就这个方法做一个简单的实例: jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异 ...

  7. JavaScript数组的五个迭代方法的简单实例

    <script> //every() var nums = [1,2,3,4,5]; var result = nums.every(function eve(item,index,arr ...

  8. java 工厂方法模式简单实例

    工厂方法模式:也叫工厂模式,属于类创建型模式,工厂父类(接口)负责定义产品对象的公共接口,而子类工厂则负责创建具体的产品对象. 目的:是为了把产品的实例化操作延迟到子类工厂中完成,通过工厂子类来决定究 ...

  9. JBox - 模态窗口,工具提示和消息 jQuery 插件

    jBox 是一个强大而灵活的 jQuery 插件,可以帮助实现模态窗口,工具提示,通知和更多的功能.你可以使用 jQuery 选择器轻松地添加工具提示效果到元素上,您可以以同样的方式设置模态窗口.该库 ...

随机推荐

  1. Readonly and other things about C++

    1. in c# readonly can be delayed to initialize in constructor. 2. in c++ totally no readonly. Many p ...

  2. Android面试题(文章内容来自他人博客)

    腾讯面试题 1.int a = 1; int result = a+++3<<2; 2.int a = 2; int result = (a++ > 2)?(++a):(a+=3); ...

  3. SQL判断一个数是整数还是小数

    DECLARE @number1 AS numeric(10,2),@number2 AS numeric(10,2) SELECT @number1=10.00,@number2=10.2 SELE ...

  4. 深入浅出Node.js (7) - 网络编程

    7.1 构建TCP服务 7.1.1 TCP 7.1.2 创建TCP服务器端 7.1.3 TCP服务的事件 7.2 构建UDP服务 7.2.1 创建UDP套接字 7.2.2 创建UDP服务器端 7.2. ...

  5. 40 个超棒的免费 Bootstrap HTML5 网站模板

    Bootstrap 是快速开发Web应用程序的前端工具包.它是一个CSS和HTML的集合,它使用了最新的浏览器技术,给你的Web开发提供了时尚的版式,表单,buttons,表格,网格系统等等. 目前 ...

  6. 关于overload和override

    override 覆盖,表示在子类中一个函数覆盖基类中的同名函数,或者局部的某个函数覆盖了全局的某个同名函数.被覆盖的函数通常不能直接被调用,必须借助一些显式的强制手段. overload 重载,表示 ...

  7. HDU 4444 Walk (离散化建图+BFS+记忆化搜索) 绝对经典

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4444 题意:给你一些n个矩形,给你一个起点,一个终点,要你求从起点到终点最少需要转多少个弯 题解:因为 ...

  8. vbox下centos安装增加功能失败

    一般都是:unable to find the sources of your current Linux kernel. 先尝试这个吧:yum install kernel kernel-heade ...

  9. 【leetcode】Merge Sorted Array(合并两个有序数组到其中一个数组中)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  10. Sonar入门(五):使用 Sonar 进行代码质量管理

    Sonar 概述 Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具. 与持续集成工具(例如 Hudson/Jenkins ...