0

私はこのコードを持っています

<html>
<head>

<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>

<script type = "text/javascript">
function MyFunc(obj,method){
    // obj.hide("slow"); // This part is working fine i.e. it is hiding the paragraph
    obj + "." + method + "(\"slow\")"; // This is not working

$(function(){
    $("#pid1").click(function(){
        MyFunc($("#pid1"),"hide");
    });
});

</script

</head>

<body>
<p id = "pid1">Test Paragraph</p>
</body>

</html>

つまり、パラメーターを jquery hide 関数に渡し、正しい文字列を形成してエフェクトを呼び出したいのですが、上記のコードのように機能しません。何か不足していますか?

4

1 に答える 1

1

角かっこを使用して、文字列でオブジェクトのプロパティにアクセスできます。

function MyFunc(obj, method) {
    obj[method]("slow"); 
}

また、 の右中括弧を忘れたことにも注意してくださいMyFunc

現在行っていることは、文字列の束をオブジェクトと連結して、文字列を生成することです。エラーは発生しませんが、何もしません。

于 2012-06-18T08:03:33.983 に答える