美元符号未定义

时间:2017-08-13 23:44:35

标签: javascript jquery html

我搜索了一个答案,但还没有一个适合。我是网站建设的新手。我正在构建一个标签功能,用于更改页面上的内容(代码来自https://codepen.io/cssjockey/pen/jGzuK

当我在我的尝试中。我收到一条错误,指出'$' is undefined。 这是我的代码

的index.html

<!DOCTYPE html>
<html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Site</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<script language="JavaScript" src="functions.js"></script>
</head>
<body>
<div class="container">

<ul class="tabs">
    <li class="tab-link current" data-tab="tab-1">TabA</li>
    <li class="tab-link" data-tab="tab-2">TabB</li>
    <li class="tab-link" data-tab="tab-3">TabC</li>
    <li class="tab-link" data-tab="tab-4">TabD</li>
</ul>

<div id="tab-1" class="tab-content current">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div id="tab-2" class="tab-content">
     Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="tab-3" class="tab-content">
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</div>
<div id="tab-4" class="tab-content">
    Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>

functions.js

$(document).ready(function(){

$('ul.tabs li').click(function(){
    var tab_id = $(this).attr('data-tab');

    $('ul.tabs li').removeClass('current');
    $('.tab-content').removeClass('current');

    $(this).addClass('current');
    $("#"+tab_id).addClass('current');
})

})

我感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:2)

这是因为美元符号(public class ConnexionActivity extends AppCompatActivity { Button b_bb, b_back, ee, b_inscrp_formulaire, fb; EditText tb_pseudo, tb_mdp; int id; String name, gender, email, birthday; private LoginButton loginButton; private CallbackManager callbackManager; Profile profile; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); /*List<String> permissionNeeds = Arrays.asList("user_photos", "email", "user_birthday", "public_profile", "AccessToken");*/ setContentView(R.layout.activity_connexion); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setTitle(""); setSupportActionBar(toolbar); b_inscrp_formulaire = (Button) findViewById(R.id.b_inscrip_formulaire); fb = (Button) findViewById(R.id.fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setText(""); loginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends", "user_birthday")); //"user_photos", "email","user_birthday", "public_profile" loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { graphRequest(loginResult.getAccessToken()); } @Override public void onCancel() { Toast.makeText(getApplicationContext(), "Non-Connecté : connexion interrupu!!", Toast.LENGTH_LONG).show(); } @Override public void onError(FacebookException error) { Toast.makeText(getApplicationContext(), "Non-Connecté : Erreur de connexion!!", Toast.LENGTH_LONG).show(); } }); b_bb = (Button) findViewById(R.id.b_bb); b_back = (Button) findViewById(R.id.b_back); tb_pseudo = (EditText) findViewById(R.id.textbox_pseudo); tb_mdp = (EditText) findViewById(R.id.textbox_mdp); ///////////// ee = (Button) findViewById(R.id.button); //////////// b_bb.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { b_bb.setBackgroundResource(R.drawable.button_bb_selec); break; } case MotionEvent.ACTION_UP: { b_bb.setBackgroundResource(R.drawable.button_bb); break; } } return false; } }); b_bb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isAuthorized()) { Intent menu_p = new Intent(ConnexionActivity.this, MenuPActivity.class); menu_p.putExtra("pseudo", tb_pseudo.getText().toString()); startActivity(menu_p); } else { openDialog(); } } }); b_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ConnexionActivity.this.finish(); } }); ee.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent menu_p = new Intent(ConnexionActivity.this, MenuPActivity.class); menu_p.putExtra("pseudo", "Easter"); startActivity(menu_p); } }); b_inscrp_formulaire.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent menu_p = new Intent(ConnexionActivity.this, InscriptionActivity.class); startActivity(menu_p); } }); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { graphRequest(loginResult.getAccessToken()); Intent menu_p = new Intent(ConnexionActivity.this, MenuPActivity.class); menu_p.putExtra("pseudo", profile.getFirstName()); startActivity(menu_p); Toast.makeText(getApplicationContext(), "Connecté : " + profile.getFirstName() + " " + profile.getLastName(), Toast.LENGTH_LONG).show(); } @Override public void onCancel() { Toast.makeText(getApplicationContext(), "Non-Connecté : connexion interrupu!!", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException error) { Toast.makeText(getApplicationContext(), "Non-Connecté : Erreur de connexion!!", Toast.LENGTH_SHORT).show(); } }); fb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LoginManager.getInstance().logInWithReadPermissions(ConnexionActivity.this, Arrays.asList("public_profile","user_friends", "email")); /*facebook permissions : "user_photos", "email", "user_birthday", "public_profile"*/ profile = Profile.getCurrentProfile().getCurrentProfile(); //to verify if a login happened or not!! if (profile != null) { // user has logged in } else { // user has not logged in } } }); //To log out of FB: /*LoginManager.getInstance().logOut();*/ //TODO: check if the user is logged in or not /* profile = Profile.getCurrentProfile().getCurrentProfile(); if (profile != null) { // user has logged in } else { // user has not logged in }*/ } private Boolean isAuthorized() { if (tb_pseudo.getText().toString().equals("Admin") && tb_mdp.getText().toString().equals("0000") ) { return true; } else return false; } public void openDialog() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("Mauvaise combinaison \"Pseudo\", \"Mot de passe\""); alertDialogBuilder.setPositiveButton("ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } public void graphRequest(AccessToken token) { GraphRequest request = GraphRequest.newMeRequest(token, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { //showing infos about the connected client!! //Toast.makeText(getApplicationContext(), object.toString(), Toast.LENGTH_LONG).show(); } }); Bundle b = new Bundle(); b.putString("fields", "id,email,first_name,last_name,picture.type(large)"); request.setParameters(b); request.executeAsync(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } } )适用于jQuery library usage.

要将其包含在项目中,只需从CDN中导入:

$

因此,您的所有<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> 标记应该如下所示:

<head>