我有一个使用Materialisecss和PHP的代码。我想通过返回Php代码打开一些模态。例如代码是4是等错密码等。
但我从不满足于展示模态甚至尝试本网站上显示的几条建议。
你能帮助我吗?
以下是我的代码的一部分:
<?php
....
else {
echo "<script>$('#modalWrongPassword').fadeIn('show');</script>";
}
}
?>
...
<div id="modalWrongPassword" class="modal">
<div class="modal-content">
<h4>Hatalı şifre</h4>
<p>A bunch of text</p>
</div>
<div class="modal-footer">
<a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Kapat</a>
</div>
</div>
...
<script type="text/javascript" src="../js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../js/materialize.min.js"></script>
<script src="../js/jquery-2.js"></script>
<script>if (!window.jQuery) { document.write('<script src="bin/jquery-2.1.1.min.js"><\/script>'); }</script>
<script src="../js/jquery.js"></script>
<script src="../js/prism.js"></script>
<script src="../js/lunr.js"></script>
<script src="../js/materialize1.js"></script>
<script src="../js/init1.js"></script>
...
答案 0 :(得分:1)
使用Materialisecss,无法像您尝试的那样打开模态
List<Notes> notes;
OnItemClickListener mItemClickListener;
private static final int TYPE_CATEGOORY = 0;
private static final int TYPE_ITEM = 1;
String changing = "";
public OneNoteAdapter(List<Notes> logs) {
this.notes = logs;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if(viewType == TYPE_CATEGOORY){
View itemView = LayoutInflater.
from(parent.getContext()).
inflate(R.layout.category_header, parent, false);
return new HeaderViewHolder(itemView);
}else{
View itemView = LayoutInflater.
from(parent.getContext()).
inflate(R.layout.learn_card, parent, false);
return new ItemViewHolder(itemView);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if(holder instanceof HeaderViewHolder){
Notes note = notes.get(position);
((HeaderViewHolder) holder).vCategoryText.setText(note.category);
}else {
ItemViewHolder item = (ItemViewHolder) holder;
Notes note = notes.get(position);
item.vNotesNote.setText(note.notes);
item.vNotesCat.setText(note.category);
}
}
@Override
public int getItemViewType(int position) {
if((!(notes.get(position).category).equals(changing))){
changing = notes.get(position).category;
return TYPE_CATEGOORY;
}else{
return TYPE_ITEM;
}
}
@Override
public int getItemCount() {
return notes.size();
}
public class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
protected TextView vNotesNote, vNotesCat;
private final Context context;
public ItemViewHolder(View itemView) {
super(itemView);
vNotesNote = (TextView) itemView.findViewById(R.id.notes_notes);
vNotesCat = (TextView) itemView.findViewById(R.id.notes_category);
context = itemView.getContext();
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(mItemClickListener != null){
mItemClickListener.onItemClick(v, getPosition());
}
}
}
public class HeaderViewHolder extends RecyclerView.ViewHolder {
protected TextView vCategoryText;
public HeaderViewHolder(View itemView) {
super(itemView);
vCategoryText = (TextView) itemView.findViewById(R.id.category_header_text);
}
}
public interface OnItemClickListener{
public void onItemClick(View v, int poition);
}
public void setOnItemClickListener (final OnItemClickListener mItemClickListener){
this.mItemClickListener = mItemClickListener;
}
以下是reference如何通过JavaScript以编程方式显示Materialisecss Modal
echo "<script>$('#modalWrongPassword').fadeIn('show');</script>";
注意:确保只包含一次jQuery和其他JS库,例如你在文档中多次包含jQuery和Materialize JS。