小编red*_*dan的帖子

带外部js文件的警报消息

我有一个带有代码的外部test.js文件:

$(document).ready(function() {
    alert("I am an alert box2!");   
});


function show_alert()
{
    alert("hihi");
}
Run Code Online (Sandbox Code Playgroud)

在我的.html中,我包含了test.js,jquery文件,还有一个按钮.单击它时,show_alert()将调用函数并且它可以正常工作.但是,消息"我是一个警报框2!" 没有解雇.
另外,如果我将document.ready函数放在我的.html中<script>... </script>.有用.我的代码有什么问题?外部文件不支持?

jquery

4
推荐指数
1
解决办法
1万
查看次数

4
推荐指数
1
解决办法
4万
查看次数

javascript/jQuery中函数定义的差异

版本1:

function add(){
var a = 2;
...
...
...
}
Run Code Online (Sandbox Code Playgroud)

版本2:

$(function(){
var ...
..
..
});
Run Code Online (Sandbox Code Playgroud)

两个版本的主要区别在哪里?对于版本2,它没有函数名称.如果只是简单地运行函数中的代码,为什么不删除$function(){..};.这真让我感到困惑,因为现在很多脚本都是以版本2的风格编写的.请帮助澄清我的困惑.

javascript jquery

4
推荐指数
1
解决办法
3526
查看次数

Any ways to reduce the repeated patterns of code in php

I have some codes here

if ($brand == "Kumiai Dairies" || $brand == "Anlene" || $brand == "Yoplait" || $brand == "Hokkaido Hidaka" 
|| $brand == "Jacob's" || $brand == "V8" || $brand == "Cow & Gate"){
do something here;
}
Run Code Online (Sandbox Code Playgroud)

Is there any way to prevent repeating $brand == "xxx"??

php

1
推荐指数
2
解决办法
72
查看次数

EditText的setText时为空指针

Thsi是我的代码:

EditText editCategoryName, editBrandName;
    private ArrayAdapter<String> myAdapter1, myAdapter2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//      mylist = new ArrayList<HashMap<String, String>>();
//      mylist2 = new ArrayList<HashMap<String, String>>();
        myList1 = new ArrayList<String>();
        myList2 = new ArrayList<String>();
        editCategoryName = (EditText)findViewById(R.id.editCategoryName);
        editBrandName = (EditText)findViewById(R.id.editBrandName);
        editCategoryName.setText("Google is your friend.", TextView.BufferType.EDITABLE);

<EditText
        android:id="@+id/editCategoryName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="???????"
        android:singleLine="true" >
    </EditText>

    <TextView
        android:id="@+id/textSpinnerBrand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="hint" />

    <Spinner
        android:id="@+id/spinnerBrand"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/editBrandName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="hint"
        android:singleLine="true" >
    </EditText>
Run Code Online (Sandbox Code Playgroud)

空指针错误显示在行中:

editCategoryName.setText("Google is your friend.", TextView.BufferType.EDITABLE);
Run Code Online (Sandbox Code Playgroud)

我不知道为什么.请帮忙..

android

0
推荐指数
1
解决办法
1250
查看次数

标签 统计

jquery ×2

android ×1

javascript ×1

mysql ×1

php ×1