jquery的问题:如果调用修改JS里的参数值?

首页index.php中开始写如下代码:
<script type="text/javascript">
$(document).ready(function() {
$('img').jqPuzzle(); // apply to all images
});
</script>

※ body中加了个按钮,想调用jqPuzzle()修改IMG的属性,参数具体如下

◎以下是引用的JS中的一段代码:
$(document).ready(function() {
$('img.jqPuzzle').each(function() {
var microFormat = /\bjqp(-[a-z]{2})?-r(\d)-c(\d)(-h(\d+))?(-s(\d+))?(-[A-Z]+)?\b/;
var match = microFormat.exec(this.className);
var settings;
if(match) {
settings = {
rows: parseInt(match[2]),
cols: parseInt(match[3]),
hole: parseInt(match[5]) || null,
shuffle: match[8] && match[8].indexOf('S') != -1,
numbers: match[8] ? match[8].indexOf('N') == -1 : true,
language: match[1] && match[1].substring(1)
};
if(match[7]) {
settings.animation = {};
settings.animation.shuffleRounds = parseInt(match[7]);
}
if(match[8] && match[8].search(/[ABCDE]/) != -1) {
settings.control = {};
settings.control.shufflePieces = match[8].indexOf('A') == -1;
settings.control.toggleOriginal = match[8].indexOf('B') == -1;
settings.control.toggleNumbers = match[8].indexOf('C') == -1;
settings.control.counter = match[8].indexOf('D') == -1;
settings.control.timer = match[8].indexOf('E') == -1;
}
}
// call the plugin
$(this).jqPuzzle(settings);
});
});
---------------
现在的问题是:如果通过调用jqPuzzle(),修改参数settings呢?
<button onclick="jqPuzzle('jqp-fr-r4-c4-h5-NDE')">b1</button>
这样写不起作用,为什么呢

哥哥姐姐救救我!!!!!!!!非常感谢,急

jqPuzzle settings 参数是一个对象
settings = {rows: ,cols: parseInt(match[3]),
hole: parseInt(match[5]) || null,
shuffle: match[8] && match[8].indexOf('S') != -1,
numbers: match[8] ? match[8].indexOf('N') == -1 : true,
language: match[1] && match[1].substring(1)
};

看你要修改谁的图片属性了。如果是被点击按钮自己的那么简单了。直接追加一个修改img src的js就好了。
但是你是按钮点击 执行 jqPuzzle ,jqPuzzle前提需要一个DOM对象,照代码来看该DOM对象应该是一个IMG
你应该
<button onclick="$('img').jqPuzzle()">b1</button>

如果你想要改变图片路径。那么你需要修改jqPuzzle 里面setting 和里面 实现。
如settings:
settings = {rows: ,cols: parseInt(match[3]),
hole: parseInt(match[5]) || null,
shuffle: match[8] && match[8].indexOf('S') != -1,
numbers: match[8] ? match[8].indexOf('N') == -1 : true,
language: match[1] && match[1].substring(1),
Img:''
};
if (settings.img!='') {
$(this).attr("src",setting['img'])
}
温馨提示:答案为网友推荐,仅供参考
相似回答