<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
alert ("good");
$.getJSON("http://localhost/index.php/users", function(json){
$.each(json, function(idx, obj) {
alert(obj.name);
});
});
});
});
</script>
json格式:
[{"user_id":"2","username":"guest2","name":"John","profile_pic":""},{"user_id":"1","username":"guest","name":"tom","profile_pic":""}]
json的格式对于解析非常重要,一定要规范化
Computer has revolutionized the world and programming is the most important tool to make our dream come true;
Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts
Tuesday, April 7, 2015
Wednesday, March 18, 2015
javascipt 模拟测试
12*12=?11*11=? 这个结果和实际不相符的原因是blgspot可能对html进行了加工,在正常的网页中正常显示
document.forms[0];是指获取第一个form
另外,这种单选框的name必须一直才能保证单选显示效果: 12*12=?
11*11=?
Monday, March 16, 2015
格式化代码
using pre tag: <pre class="brush: java"></pre>
// Comment
public class Testing {
public Testing() {
}
public void Method() {
/* Another Comment
on multiple lines */
int x = 9;
}
}
Monday, February 9, 2015
一个简单 javascript计算器的实现
<input id="kkk" />
<br />
<button id="1" onclick="reply_click(this.value)" value="1">1</button>
<button id="2" onclick="reply_click(this.id)">2</button>
<button id="3" onclick="reply_click(this.id)">3</button>
<button id="4" onclick="reply_click(this.id)">4</button>
<button id="5" onclick="reply_click(this.id)">5</button>
<button id="6" onclick="reply_click(this.id)">6</button>
<button id="7" onclick="reply_click(this.id)">7</button>
<button id="8" onclick="reply_click(this.id)">8</button>
<button id="9" onclick="reply_click(this.id)">9</button>
<button id="0" onclick="reply_click(this.id)">0</button>
<br />
<button id="equal" onclick="compute()">=</button>
<button onclick="reply_click(this.value)" value="+">+</button>
<button onclick="reply_click(this.value)" value="-">-</button>
<button onclick="reply_click(this.value)" value="*">*</button>
<button onclick="reply_click(this.value)" value="/">/</button>
<button onclick="reset()">C</button>
<script type="text/javascript">
function reply_click(clicked_id)
{
document.getElementById("kkk").value+=clicked_id;
}
function compute()
{
document.getElementById("kkk").value = eval(document.getElementById("kkk").value);
}
function reset()
{
document.getElementById("kkk").value="";
}
</script>
效果见
<br />
<button id="1" onclick="reply_click(this.value)" value="1">1</button>
<button id="2" onclick="reply_click(this.id)">2</button>
<button id="3" onclick="reply_click(this.id)">3</button>
<button id="4" onclick="reply_click(this.id)">4</button>
<button id="5" onclick="reply_click(this.id)">5</button>
<button id="6" onclick="reply_click(this.id)">6</button>
<button id="7" onclick="reply_click(this.id)">7</button>
<button id="8" onclick="reply_click(this.id)">8</button>
<button id="9" onclick="reply_click(this.id)">9</button>
<button id="0" onclick="reply_click(this.id)">0</button>
<br />
<button id="equal" onclick="compute()">=</button>
<button onclick="reply_click(this.value)" value="+">+</button>
<button onclick="reply_click(this.value)" value="-">-</button>
<button onclick="reply_click(this.value)" value="*">*</button>
<button onclick="reply_click(this.value)" value="/">/</button>
<button onclick="reset()">C</button>
<script type="text/javascript">
function reply_click(clicked_id)
{
document.getElementById("kkk").value+=clicked_id;
}
function compute()
{
document.getElementById("kkk").value = eval(document.getElementById("kkk").value);
}
function reset()
{
document.getElementById("kkk").value="";
}
</script>
效果见
Subscribe to:
Posts (Atom)
