我在通过小书签附加的表单内的页面上获取可用的 php 变量时遇到问题
书签代码:
<a class="bookmarklet" href="javascript:(function(){var%20script=document.createElement('script');script.src='http://webcreationcentre.com.au/manage/manage.js';document.body.appendChild(script);})()">title checker</a>
manage.js 代码:
(function(){
// the minimum version of jQuery we want
var v = "1.3.2";
// check prior inclusion and version
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initMyBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initMyBookmarklet();
}
function initMyBookmarklet() {
(window.myBookmarklet = function() {
var title = '<?php echo $data->title; ?>';
alert(title);
$('body').append($('<div></div>').css('width','100%')
.append($('<form></form>')
.append($('<label for="title">Title</label>'))
.append($('<input type="text" name="title" value="<?php echo $data->title; ?>">'))));
// your JavaScript code goes here!
})();
}
})();