`
wutao8818
  • 浏览: 607764 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

使用豆瓣api查书的js

    博客分类:
  • js
阅读更多
jquery版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>Books: new</title>
  <link href="/stylesheets/scaffold.css?1221735418" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://www.douban.com/js/api.js?v=2"></script>
<script type="text/javascript" src="http://www.douban.com/js/api-parser.js?v=1"></script>
<script type="text/javascript" src="/javascripts/jquery.js"></script>
<script type="text/javascript" src="/javascripts/book.js"></script>
</head>
<body>
<p style="color: green"></p>

添加新书到共享书库

输入ISBN:

<form action="/books" class="new_book" id="new_book" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="267739a8b520f804aef589dfc650dc7363f3d3c3" /></div>
  
  <p>
    <label for="book_isbn">Isbn</label><br />
    <input id="book_isbn" name="book[isbn]" size="30" type="text" />
  </p>

  <p>
    <label for="book_name">Name</label><br />
    <input id="book_name" name="book[name]" size="30" type="text" />
  </p>
  <p>
    <input id="book_submit" name="commit" type="submit" value="保存" />
  </p>
</form>



</body>
</html>



DOUBAN.apikey = '09c72190e1b75ed51d5564b2a5261c7f'
$().ready(function(){
    $("#book_isbn").focus();
    var isbn=$("#book_isbn").get(0).value;
 
    $("#book_isbn").blur(function (){
        DOUBAN.searchBooks({
            keyword:isbn,
            callback:function(book){
                var list = DOUBAN.parseSubjects(book).entries;
                if(list===null||list.length==0){
                    $("#book_name").get(0).value="无此书可查";
                }else{
                    var title=list[0].title;
                    $("#book_name").get(0).value=title;
                }
            }
        })
        
    });
})

我的新站 http://findbook.8800.org
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics